package com.jsj.controller;

import com.jsj.pojo.Notice;
import com.jsj.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

//通知公告
@Controller
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    //查询所有公告
    @RequestMapping(value = {"/queryAllNotice","queryAllNotice111"})
    @ResponseBody
    public List queryAllNotice(){
        List list = noticeService.queryAllNotice();
        return list;
    }
    //查询该管理员的公告
    @RequestMapping(value = {"/querySenderNotice"})
    @ResponseBody
    public List querySenderNotice(int senderId){
        List list = noticeService.querySenderNotice(senderId);
        return list;
    }
    //关键字搜索
    @RequestMapping(value = {"/queryNotice"})
    @ResponseBody
    public List queryNotice(String str){
        List list = noticeService.queryNotice(str);
        return list;
    }



//添加公告
    @RequestMapping("addNoticeById")
    @ResponseBody
    public Boolean addNoticeById(int senderId,String senderName,String title,String content,String sendDate) throws ParseException {

        Notice notice = new Notice();
        notice.setSenderId(senderId);
        notice.setSenderName(senderName);
        notice.setTitle(title);
        notice.setContent(content);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date sendDate2 = format.parse(sendDate);
        notice.setSendDate(sendDate2);
        Boolean aBoolean = noticeService.addNoticeById(notice);

        return aBoolean;
    }

    @RequestMapping("updateByNoticeId")
    @ResponseBody
    public Boolean updateByNoticeId(int noticeId, int senderId,String senderName,String title,String content,String sendDate) throws ParseException {

        Notice notice = new Notice();
        notice.setNoticeId(noticeId);

        notice.setSenderId(senderId);
        notice.setSenderName(senderName);
        notice.setTitle(title);
        notice.setContent(content);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date sendDate1 = format.parse(sendDate);
        notice.setSendDate(sendDate1);
        Boolean aBoolean = noticeService.updateByNoticeId(notice);
            return aBoolean;
    }

    //删除公告
    @RequestMapping("/delByNoticeId")
    @ResponseBody
    public Boolean delByNoticeId(int noticeId){
        Boolean aBoolean = noticeService.delByNoticeId(noticeId);
        return aBoolean;

    }


}
